<template>
	<view>
		<view class="cu-bar search bg-white">
			<view class="search-form round" style="text-align: center;">
				<input @submit.prevent="search" v-model="searchTxt" :adjust-position="false" type="text" placeholder="联系人姓名"
				 confirm-type="search"></input>
			</view>
		</view>

		<view class="cu-list menu-avatar" v-if="list!=null" v-for="item in list" :key="item.friendUserId">
			<view class="cu-item" @tap="tapOne(item)">
				<view class="cu-avatar round lg" :style="'background-image:url('+ item.friendFaceImage +');'"></view>
				<view class="content">
					<view class="text-grey">{{item.friendUsername}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		onTabItemTap() {
			this.userId = this.$tool.getStorageSync("userInfo").id
			this.getFriendsList()
		},
		data() {
			return {
				userId: null,
				searchTxt: null,
				list: []
			};
		},
		methods: {
			async search() {
			},
			async getFriendsList() {
				var res = await this.$request({ // 发送异步请求
					baseURL: this.$tool.serverURL,
					url: 'user/myFriends',
					params: {
						userId: this.userId
					},
					type: 'get'
				})
				if (res.status == 200) {
					this.list = res.data
					this.$tool.setContactList(res.data)// 将联系人列表存到缓存中
				}
			},
			tapOne(user) {
				uni.navigateTo({
					url:`../chat/chat?user=${encodeURIComponent(JSON.stringify(user))}`
				})
			}
		}
	}
</script>

<style>
</style>
